import React from "react";
import View from "../base/View";
import defaultData from "./data";
import './index.less';
import {ImgUpload} from "../../../../common/fileupload";
import {viewTypes} from "../../../../../constants/form";

const { MOBILE_WX, MOBILE } = viewTypes;

export default class PictureView extends View {
  renderContent(data, value) {
    const { viewType } = this.props;
    //const iswx = isWX() || isWXWork();

    // 正在初始化微信接口
    // if (iswx && MOBILE === viewType) {
    //   return null;
    // };

    return (
      <ImgUpload
        maxNum={data.maxNum}
        iswx={MOBILE_WX === viewType}
        onChange={this.handleValueChange}
        onUploading={this.toggleFooterDisable}
        files={value}
      />
    );
  }


  renderForReadonly(data, value) {
    const files = value;
    return (
        <div className={'wea-edc-upload-img'}>
          {
            files.map(({img, link}) => (
                <div className={`wea-edc-upload-container`} onClick={() => {window.open(link, '_blank')}}>
                  <div className='clearfix wea-edc-upload-item'>
                    <div className='wea-edc-upload-file-img'><img src={img}/></div>
                  </div>
                </div>
            ))
          }
        </div>

    );
  }
}

PictureView.defaultProps = {
  data: defaultData,
  value: ''
};